package CI.aufgabe2.cip.mynodes;

import CI.aufgabe2.cip.SymbolTable;
import CI.aufgabe2.cip.base.AbstractDescr;
import CI.aufgabe2.cip.descriptor.ArrayDescr;
import CI.aufgabe2.cip.descriptor.SimpleTypeDescr;

public class MyVarDeclarationNode extends MyAbstractNode {

	private static final long serialVersionUID = 1L;
	public final MyIdentListNode identList;
	public final MyAbstractNode type;

	public MyVarDeclarationNode(MyIdentListNode iList, MyAbstractNode t) {
		identList = iList;
		type = t;
	}

	@Override
	public void print() {
		trace("VarDeclarationNode ");
		if (identList != null)
			identList.print();
		if (type != null)
			type.print();

		unindent();
	}

	@Override
	public int getSize() {
		return identList.getSize();
	}

	public AbstractDescr compile(SymbolTable sym) {
		AbstractDescr d = null;

		if(type instanceof MyIdNode){
			String s = ((MyIdNode) type).strval;
			if(s.equals("integer")){
				d = new SimpleTypeDescr(s);
			}
			else if(s.equals("string")){
				d = new SimpleTypeDescr(s);
			}
			else{
				d = sym.getDescr(s);
			}
		}else{
			d = type.compile(sym);
		}
		
		
		identList.compile(sym, d);
		return d;
	}

}
